<!DOCTYPE html>
<html>
<head>
    <title>住院结算--中软高科-2015</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css"/>
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css"/>
    <link rel="stylesheet" type="text/css" href="../Css/style.css"/>
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <script type="text/javascript" src="../Js/jquery.sorted.js"></script>
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>
    <script type="text/javascript" src="../Js/pagination.js"></script>
    <link rel="stylesheet" type="text/css" href="../Css/pagination.css" />

    <style type="text/css">
        body {
            padding-bottom: 40px;
        }

        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }
    </style>
    <script type="text/javascript">
        $(function () {
            $('#newNav').click(function () {
                window.location.href = "dispensing-gives.html";
            });
            initData("","")
        });

        function checkall() {
            var alls = document.getElementsByName("check");
            var ch = document.getElementById("checkall");
            if (ch.checked) {
                for (var i = 0; i < alls.length; i++) {
                    alls[i].checked = true;
                }
            } else {
                for (var i = 0; i < alls.length; i++) {
                    alls[i].checked = false;
                }
            }
        }

        function delAll() {
            var alls = document.getElementsByName("check");
            var ids = new Array();
            for (var i = 0; i < alls.length; i++) {
                if (alls[i].checked) {
                    ids.push(alls[i].value);
                }
            }
            if (ids.length > 0) {
                if (confirm("确认操作?")) {
                    alert("成功!");
                }
            } else {
                alert("请选中要操作的项");
            }
        }

        //初始化数据
        function initData(id, name) {
            $.ajax({
                url: "http://localhost:8080/settle/selectHospitalSettle",
                data: {'id': id, "name": name},
                type: 'post',
                dataType: 'json',
                success: function (data) {
                    //清空下级标签
                    $("#xunhuan").empty();
                    let page = data.data.settlePage;
                    //let param = data.data.param;
                    let list = page.list;
                    console.log(list)
                    //遍历数据
                    $.each(list, function (index, item) {

                        let jisuan = "";
                        if (item.behCloseprice==0){
                            jisuan = "<a onclick='jiesuan(" + item.behId + ")' href=\"#\">结算</a>";
                        }

                        let myxunhuan = "" +
                            "<tr >\n" +
                            "         \t<td style=\"vertical-align:middle;\"><input type=\"checkbox\" name=\"check\" value=\"" + item.behId + "\"></td>\n" +
                            "            <td style=\"vertical-align:middle;\">" + item.behId + "</td>\n" +
                            "            <td style=\"vertical-align:middle;\">" + item.hosrName + "</td>\n" +
                            "            <td style=\"vertical-align:middle;\">" + item.behAntecedent + "</td>\n" +
                            "            <td style=\"vertical-align:middle;\">" + item.balance + "</td>\n" +
                            "            <td style=\"vertical-align:middle;\">" + state(item.behCloseprice) + "</td>\n" +
                            "            <td style=\"vertical-align:middle;\"><a href=\"account-look2.html?flag=1&id=" + item.behId + "\">详细信息</a>&nbsp;&nbsp;&nbsp;"+jisuan+"</td>\n" +
                            "        </tr>";
                        $("#xunhuan").append(myxunhuan);
                    });

                    //分页
                    // $("#pageNum").text(page.pageNum + "/" + page.pages);
                    // $("#totalMsg").text(page.pages);

                    new Pagination({
                        element: '#pages',
                        type: 2,
                        layout: 'prev, pager, next, total, jumper',
                        pageIndex: 1,
                        pageSize: 5,
                        pageCount: 9,
                        total: page.total,
                        singlePageHide: false,
                        disabled: true,
                        currentChange: function (index) {
                            console.log(index);

                            let id = $("input[name='id']").val();
                            let name = $("input[name='name']").val();
                            $.ajax({
                                url: "http://localhost:8080/settle/selectHospitalSettle",
                                data: {'id': id, "name": name,'pageNum':index},
                                type: 'post',
                                dataType: 'json',
                                success: function (data) {
                                    //清空下级标签
                                    $("#xunhuan").empty();
                                    let page = data.data.settlePage;
                                    //let param = data.data.param;
                                    let list = page.list;
                                    console.log(list)
                                    //遍历数据
                                    $.each(list, function (index, item) {

                                        let jisuan = "";
                                        if (item.behCloseprice==0){
                                            jisuan = "<a onclick='jiesuan(" + item.behId + ")' href=\"#\">结算</a>";
                                        }

                                        let myxunhuan = "" +
                                            "<tr >\n" +
                                            "         \t<td style=\"vertical-align:middle;\"><input type=\"checkbox\" name=\"check\" value=\"" + item.behId + "\"></td>\n" +
                                            "            <td style=\"vertical-align:middle;\">" + item.behId + "</td>\n" +
                                            "            <td style=\"vertical-align:middle;\">" + item.hosrName + "</td>\n" +
                                            "            <td style=\"vertical-align:middle;\">" + item.behAntecedent + "</td>\n" +
                                            "            <td style=\"vertical-align:middle;\">" + item.balance + "</td>\n" +
                                            "            <td style=\"vertical-align:middle;\">" + state(item.behCloseprice) + "</td>\n" +
                                            "            <td style=\"vertical-align:middle;\"><a href=\"account-look2.html?flag=1&id=" + item.behId + "\">详细信息</a>&nbsp;&nbsp;&nbsp;"+jisuan+"</td>\n" +
                                            "        </tr>";
                                        $("#xunhuan").append(myxunhuan);
                                    });
                                }
                            });
                        }
                    });
                }
            });
        }

        //状态转换
        function state(num) {
            if (num == 1) {
                return "已结算";
            }
            if (num == 0) {
                return "未结算";
            }
            return "";
        }

        //结算
        function jiesuan(id) {
            $.ajax({
                url: "http://localhost:8080/settle/updateHospitalSettleStatus",
                data: {'id': id, "status": 1},
                type: 'post',
                dataType: 'json',
                success: function (data) {
                    if (data.response.flag){
                        alert(data.data);
                    }else {
                        alert(data.response.errorMsg);
                    }
                    chaxun();
                }
            });

            return false;
        }

        //查询
        function chaxun() {
            let id = $("input[name='id']").val();
            let name = $("input[name='name']").val();
            initData(id, name)
        }

        //导出excel
        function exportExcel() {
            var ids = [];
            $("input[name='check']:checked").each(function (i) {
                ids.push($(this).val())
                //$("body").append("<p>"+$(this).val()+"</p>")
            })
            //console.log(ids)
            if (ids.length > 0) {
                $.ajax({
                    url: "http://localhost:8080/settle/exportExcel",
                    data: {"ids": ids},
                    type: 'post',
                    traditional: true,
                    success: function (resp) {
                        if (resp.response.flag) {
                            window.location.href = "http://localhost:8080/downloadFile?fileName=hospitalSettleMsg.xls"
                        } else {

                        }
                    }
                })
            } else {
                alert("请选择要导出的数据");
            }
        }
        //清空
        function qingkong(){
            initData("", "");
        }
    </script>
</head>
<body>

<form action="account.html" method="post" class="definewidth m20">
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td width="10%" class="tableleft">病例号：</td>
            <td><input type="text" name="id" value=""/></td>
            <td width="10%" class="tableleft">姓名：</td>
            <td><input type="text" name="name" value=""/></td>
        </tr>
        <tr>
            <td colspan="4">
                <center>
                    <input class="btn btn-primary" type="button" onclick="chaxun()" value="查询"/>
                    <input type="button" class="btn btn-primary" value="清空" onclick="qingkong()"/>
                </center>
            </td>
        </tr>
    </table>
</form>

<table class="table table-bordered table-hover definewidth m10">
    <thead>
    <tr>
        <th><input type="checkbox" id="checkall" onChange="checkall();"></th>
        <th>病历号</th>
        <th>姓名</th>
        <th>押金</th>
        <th>当前余额</th>
        <th>状态</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody id="xunhuan">
    <tr>
        <td style="vertical-align:middle;"><input type="checkbox" name="check" value="1"></td>
        <td style="vertical-align:middle;">1103</td>
        <td style="vertical-align:middle;">黄飞鸿</td>
        <td style="vertical-align:middle;">2000元</td>
        <td style="vertical-align:middle;">150元</td>
        <td style="vertical-align:middle;">未结算</td>
        <td style="vertical-align:middle;"><a href="account-look.html">详细信息</a>&nbsp;&nbsp;&nbsp;<a href="">结算</a></td>
    </tr>
    </tbody>
</table>

<table class="table table-bordered table-hover definewidth m10">
    <tr>
        <th colspan="5">
            <div class="inline pull-right page" id="pages">
<!--                <a href='#'>第一页</a> <a href='#'>上一页</a> <span class='current'>1</span><a href='#'>2</a><a-->
<!--                    href='/chinapost/index.php?m=Label&a=index&p=3'>3</a><a href='#'>4</a><a href='#'>5</a> <a href='#'>下一页</a>-->
<!--                <a href='#'>最后一页</a>-->
<!--                &nbsp;&nbsp;&nbsp;共<span class='current' id="totalMsg">32</span>条记录<span class='current' id="pageNum"> 1/33 </span>页-->
            </div>
            <div>
                <button type="button" class="btn btn-success" id="delPro" onclick="exportExcel()">导出Excel</button>
            </div>

        </th>
    </tr>
</table>

</body>
</html>
